/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/

#include <string.h>
#include <math.h>

#include <flgrCoreData.h>
#include <flgrCoreIO.h>
#include <flgrCoreVector.h>
#include <flgrCoreCopy.h>
#include <flgrCoreShift.h>
#include <flgrCoreDispatch.h>
#include <flgrCoreArithDef.h>
#include <flgrArith.h>
#include <flgrArithShift.h>
#include "flgrMorphoBaseFast.h"




////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Erosion
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

#define FLGR_MACRO_LINE_ERODE(dtype,lout,lin,ltmp)	\
  flgr1d_arith_inf_shift_right_##dtype(ltmp,lin, 1);	\
  flgr1d_arith_inf_shift_left_##dtype(lout,ltmp, 1)
 
#define FLGR_MACRO_LINE_RIGHT_ERODE(dtype,lout,lin,ltmp0)	\
  flgr1d_arith_inf_shift_right_##dtype(lout,lin, 1)

#define FLGR_MACRO_LINE_LEFT_ERODE(dtype,lout,lin,ltmp0)	\
  flgr1d_arith_inf_shift_left_##dtype(lout,lin, 1)

#define FLGR_MACRO_ERODE_4_CONNEXITY(dtype)				\
  FLGR_Data1D *tmp = flgr1d_create_signal_from(datsrc->row[0]);		\
  FLGR_Data1D *tmp0 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmpsav;							\
  FLGR_Data1D **pout = datdest->row;					\
  FLGR_Data1D **pin = datsrc->row;					\
  int k,j;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr1d_copy_##dtype##_##dtype(tmp0,pin[0]);				\
  flgr1d_copy_##dtype##_##dtype(tmp1,pin[1]);				\
									\
  FLGR_MACRO_LINE_ERODE(dtype,pout[0],tmp0,tmp);			\
  flgr1d_arith_inf_##dtype(pout[0],pout[0],tmp1);			\
									\
  for(j=1,k=2 ; k<datsrc->size_y ; j++,k++) {				\
    flgr1d_copy_##dtype##_##dtype(tmp2,pin[k]);				\
									\
    FLGR_MACRO_LINE_ERODE(dtype,pout[j],tmp1,tmp);			\
    flgr1d_arith_inf_##dtype(pout[j],pout[j],tmp2);			\
    flgr1d_arith_inf_##dtype(pout[j],pout[j],tmp0);			\
									\
    tmpsav=tmp0;							\
    tmp0=tmp1;								\
    tmp1=tmp2;								\
    tmp2=tmpsav;							\
  }									\
									\
  FLGR_MACRO_LINE_ERODE(dtype,pout[j],tmp1,tmp);			\
  flgr1d_arith_inf_##dtype(pout[j],pout[j],tmp0);			\
  									\
  flgr1d_destroy(tmp);							\
  flgr1d_destroy(tmp0);							\
  flgr1d_destroy(tmp1);							\
  flgr1d_destroy(tmp2)


 
void flgr2d_erode_4_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgBIT);
}
void flgr2d_erode_4_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgUINT8);
}
void flgr2d_erode_4_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgUINT16);
}
void flgr2d_erode_4_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgUINT32);
}
void flgr2d_erode_4_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgINT8);
}
void flgr2d_erode_4_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgINT16);
}
void flgr2d_erode_4_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgINT32);
}
void flgr2d_erode_4_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgFLOAT32);
}
void flgr2d_erode_4_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_4_CONNEXITY(fgFLOAT64);
}






#define FLGR_MACRO_ERODE_6_CONNEXITY(dtype)				\
  FLGR_Data1D *tmp = flgr1d_create_signal_from(datsrc->row[0]);		\
  FLGR_Data1D *tmp0 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmps;							\
  FLGR_Data1D **pout = datdest->row;					\
  FLGR_Data1D **pin = datsrc->row;					\
  FLGR_Vector *vec = flgr_vector_create(datsrc->spp,datsrc->type);	\
  dtype max=MAX_##dtype;						\
  int i;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr_vector_populate_from_scalar_##dtype(vec,max);			\
									\
  FLGR_MACRO_LINE_RIGHT_ERODE(dtype,tmp0,pin[0],tmp);			\
  FLGR_MACRO_LINE_LEFT_ERODE(dtype,tmp1,pin[1],tmp);			\
  flgr1d_shift_left_##dtype(tmp,pin[0],1,vec);				\
  flgr1d_arith_inf_##dtype(tmp,tmp0,tmp);				\
  flgr1d_arith_inf_##dtype(pout[0],tmp,tmp1);				\
									\
  for(i=1;i<datsrc->size_y-1;i++) {					\
    flgr1d_arith_inf_##dtype(tmp0,tmp0,tmp1);				\
									\
    if((i%2)==1) {							\
      flgr1d_shift_right_##dtype(tmp2,pin[i],1,vec);			\
    }else {								\
      flgr1d_shift_left_##dtype(tmp2,pin[i],1,vec);			\
    }									\
									\
    flgr1d_arith_inf_##dtype(tmp2,tmp0,tmp2);				\
    tmps=tmp0;								\
    tmp0=tmp1;								\
    tmp1=tmps;								\
    									\
    if((i%2)==1) {							\
      FLGR_MACRO_LINE_RIGHT_ERODE(dtype,tmp1,pin[i+1],tmp);		\
    }else {								\
      FLGR_MACRO_LINE_LEFT_ERODE(dtype,tmp1,pin[i+1],tmp);		\
    }									\
    									\
    flgr1d_arith_inf_##dtype(pout[i],tmp1,tmp2);			\
  }									\
  									\
									\
  i=datsrc->size_y-1;							\
  flgr1d_arith_inf_##dtype(tmp0,tmp0,tmp1);				\
  									\
  if((i%2)==1) {							\
    flgr1d_shift_right_##dtype(tmp2,pin[i],1,vec);			\
  }else	 {								\
    flgr1d_shift_left_##dtype(tmp2,pin[i],1,vec);			\
  } 									\
									\
  flgr1d_arith_inf_##dtype(pout[i],tmp0,tmp2);				\
									\
  flgr_vector_destroy(vec);						\
  flgr1d_destroy(tmp);							\
  flgr1d_destroy(tmp0);							\
  flgr1d_destroy(tmp1);							\
  flgr1d_destroy(tmp2)


void flgr2d_erode_6_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgBIT);
}
void flgr2d_erode_6_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgUINT8);
}
void flgr2d_erode_6_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgUINT16);
}
void flgr2d_erode_6_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgUINT32);
}
void flgr2d_erode_6_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgINT8);
}
void flgr2d_erode_6_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgINT16);
}
void flgr2d_erode_6_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgINT32);
}
void flgr2d_erode_6_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgFLOAT32);
}
void flgr2d_erode_6_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_6_CONNEXITY(fgFLOAT64);
}



#define FLGR_MACRO_ERODE_8_CONNEXITY(dtype)				\
  FLGR_Data1D *tmp = flgr1d_create_signal_from(datsrc->row[0]);		\
  FLGR_Data1D *tmp0 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmpsav;							\
  FLGR_Data1D **pout = datdest->row;					\
  FLGR_Data1D **pin = datsrc->row;					\
  int k,j;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  FLGR_MACRO_LINE_ERODE(dtype,tmp0,pin[0],tmp);				\
  FLGR_MACRO_LINE_ERODE(dtype,tmp1,pin[1],tmp);				\
									\
  flgr1d_arith_inf_##dtype(pout[0],tmp0,tmp1);				\
									\
  for(j=1,k=2 ; k<datsrc->size_y ; j++,k++) {				\
    FLGR_MACRO_LINE_ERODE(dtype,tmp2,pin[k],tmp);			\
    flgr1d_arith_inf_##dtype(tmp0,tmp1,tmp0);				\
    flgr1d_arith_inf_##dtype(pout[j],tmp0,tmp2);			\
									\
    tmpsav=tmp0;							\
    tmp0=tmp1;								\
    tmp1=tmp2;								\
    tmp2=tmpsav;							\
  }									\
									\
  flgr1d_arith_inf_##dtype(pout[j],tmp0,tmp1);				\
									\
  flgr1d_destroy(tmp);							\
  flgr1d_destroy(tmp0);							\
  flgr1d_destroy(tmp1);							\
  flgr1d_destroy(tmp2)


void flgr2d_erode_8_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgBIT);
}
void flgr2d_erode_8_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgUINT8);
}
void flgr2d_erode_8_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgUINT16);
}
void flgr2d_erode_8_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgUINT32);
}
void flgr2d_erode_8_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgINT8);
}
void flgr2d_erode_8_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgINT16);
}
void flgr2d_erode_8_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgINT32);
}
void flgr2d_erode_8_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgFLOAT32);
}
void flgr2d_erode_8_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_ERODE_8_CONNEXITY(fgFLOAT64);
}


////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Gradient Minus
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

void flgr2d_gradient_inner_8_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_8_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_8_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datsrc,datdest);  
}



void flgr2d_gradient_inner_4_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_4_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_4_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datsrc,datdest);  
}




void flgr2d_gradient_inner_6_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datsrc,datdest);  
}
void flgr2d_gradient_inner_6_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_6_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datsrc,datdest);  
}




////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Dilation
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

#define FLGR_MACRO_LINE_DILATE(dtype,lout,lin,ltmp)	\
  flgr1d_arith_sup_shift_right_##dtype(ltmp,lin, 1);	\
  flgr1d_arith_sup_shift_left_##dtype(lout,ltmp, 1)
 
#define FLGR_MACRO_LINE_RIGHT_DILATE(dtype,lout,lin,ltmp0)	\
  flgr1d_arith_sup_shift_right_##dtype(lout,lin, 1)

#define FLGR_MACRO_LINE_LEFT_DILATE(dtype,lout,lin,ltmp0)	\
  flgr1d_arith_sup_shift_left_##dtype(lout,lin, 1)


#define FLGR_MACRO_DILATE_4_CONNEXITY(dtype)				\
  FLGR_Data1D *tmp = flgr1d_create_signal_from(datsrc->row[0]);		\
  FLGR_Data1D *tmp0 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmpsav;							\
  FLGR_Data1D **pout = datdest->row;					\
  FLGR_Data1D **pin = datsrc->row;					\
  int k,j;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr1d_copy_##dtype##_##dtype(tmp0,pin[0]);				\
  flgr1d_copy_##dtype##_##dtype(tmp1,pin[1]);				\
									\
  FLGR_MACRO_LINE_DILATE(dtype,pout[0],tmp0,tmp);			\
  flgr1d_arith_sup_##dtype(pout[0],pout[0],tmp1);			\
									\
  for(j=1,k=2 ; k<datsrc->size_y ; j++,k++) {				\
    flgr1d_copy_##dtype##_##dtype(tmp2,pin[k]);				\
									\
    FLGR_MACRO_LINE_DILATE(dtype,pout[j],tmp1,tmp);			\
    flgr1d_arith_sup_##dtype(pout[j],pout[j],tmp2);			\
    flgr1d_arith_sup_##dtype(pout[j],pout[j],tmp0);			\
									\
    tmpsav=tmp0;							\
    tmp0=tmp1;								\
    tmp1=tmp2;								\
    tmp2=tmpsav;							\
  }									\
									\
  FLGR_MACRO_LINE_DILATE(dtype,pout[j],tmp1,tmp);			\
  flgr1d_arith_sup_##dtype(pout[j],pout[j],tmp0);			\
									\
  									\
  flgr1d_destroy(tmp);							\
  flgr1d_destroy(tmp0);							\
  flgr1d_destroy(tmp1);							\
  flgr1d_destroy(tmp2)
 
 
void flgr2d_dilate_4_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgBIT);
}
void flgr2d_dilate_4_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgUINT8);
}
void flgr2d_dilate_4_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgUINT16);
}
void flgr2d_dilate_4_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgUINT32);
}
void flgr2d_dilate_4_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgINT8);
}
void flgr2d_dilate_4_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgINT16);
}
void flgr2d_dilate_4_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgINT32);
}
void flgr2d_dilate_4_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgFLOAT32);
}
void flgr2d_dilate_4_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_4_CONNEXITY(fgFLOAT64);
}






#define FLGR_MACRO_DILATE_6_CONNEXITY(dtype)				\
  FLGR_Data1D *tmp = flgr1d_create_signal_from(datsrc->row[0]);		\
  FLGR_Data1D *tmp0 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmps;							\
  FLGR_Data1D **pout = datdest->row;					\
  FLGR_Data1D **pin = datsrc->row;					\
  FLGR_Vector *vec = flgr_vector_create(datsrc->spp,datsrc->type);	\
  dtype min = MIN_##dtype;						\
  int i;								\
  									\
  FLGR_DECLARE_FUNCTION;						\
									\
  flgr_vector_populate_from_scalar_##dtype(vec,min);			\
  									\
  FLGR_MACRO_LINE_RIGHT_DILATE(dtype,tmp0,pin[0],tmp);			\
  FLGR_MACRO_LINE_LEFT_DILATE(dtype,tmp1,pin[1],tmp);			\
  flgr1d_shift_left_##dtype(tmp,pin[0],1,vec);				\
  flgr1d_arith_sup_##dtype(tmp,tmp0,tmp);				\
  flgr1d_arith_sup_##dtype(pout[0],tmp,tmp1);				\
									\
  for(i=1;i<datsrc->size_y-1;i++) {					\
    flgr1d_arith_sup_##dtype(tmp0,tmp0,tmp1);				\
									\
    if((i%2)==1) {							\
      flgr1d_shift_right_##dtype(tmp2,pin[i],1,vec);			\
    }else {								\
      flgr1d_shift_left_##dtype(tmp2,pin[i],1,vec);			\
    }									\
									\
    flgr1d_arith_sup_##dtype(tmp2,tmp0,tmp2);				\
    tmps=tmp0;								\
    tmp0=tmp1;								\
    tmp1=tmps;								\
    									\
    if((i%2)==1) {							\
      FLGR_MACRO_LINE_RIGHT_DILATE(dtype,tmp1,pin[i+1],tmp);		\
    }else {								\
      FLGR_MACRO_LINE_LEFT_DILATE(dtype,tmp1,pin[i+1],tmp);		\
    }									\
    									\
    flgr1d_arith_sup_##dtype(pout[i],tmp1,tmp2);			\
  }									\
  									\
									\
  i=datsrc->size_y-1;							\
  flgr1d_arith_sup_##dtype(tmp0,tmp0,tmp1);				\
  									\
  if((i%2)==1) {							\
    flgr1d_shift_right_##dtype(tmp2,pin[i],1,vec);			\
  }else	 {								\
    flgr1d_shift_left_##dtype(tmp2,pin[i],1,vec);			\
  } 									\
									\
  flgr1d_arith_sup_##dtype(pout[i],tmp0,tmp2);				\
									\
  flgr_vector_destroy(vec);						\
  flgr1d_destroy(tmp);							\
  flgr1d_destroy(tmp0);							\
  flgr1d_destroy(tmp1);							\
  flgr1d_destroy(tmp2)


void flgr2d_dilate_6_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgBIT);
}
void flgr2d_dilate_6_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgUINT8);
}
void flgr2d_dilate_6_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgUINT16);
}
void flgr2d_dilate_6_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgUINT32);
}
void flgr2d_dilate_6_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgINT8);
}
void flgr2d_dilate_6_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgINT16);
}
void flgr2d_dilate_6_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgINT32);
}
void flgr2d_dilate_6_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgFLOAT32);
}
void flgr2d_dilate_6_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_6_CONNEXITY(fgFLOAT64);
}




#define FLGR_MACRO_DILATE_8_CONNEXITY(dtype)				\
  FLGR_Data1D *tmp = flgr1d_create_signal_from(datsrc->row[0]);		\
  FLGR_Data1D *tmp0 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *tmp2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D **pout = datdest->row;					\
  FLGR_Data1D **pin = datsrc->row;					\
  FLGR_Data1D *tmpsav;							\
  int k,j;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  FLGR_MACRO_LINE_DILATE(dtype,tmp0,pin[0],tmp);			\
  FLGR_MACRO_LINE_DILATE(dtype,tmp1,pin[1],tmp);			\
									\
  flgr1d_arith_sup_##dtype(pout[0],tmp0,tmp1);				\
									\
  for(j=1,k=2 ; k<datsrc->size_y ; j++,k++) {				\
    FLGR_MACRO_LINE_DILATE(dtype,tmp2,pin[k],tmp);			\
    flgr1d_arith_sup_##dtype(tmp0,tmp1,tmp0);				\
    flgr1d_arith_sup_##dtype(pout[j],tmp0,tmp2);			\
									\
    tmpsav = tmp0;							\
    tmp0 = tmp1;							\
    tmp1 = tmp2;							\
    tmp2 = tmpsav;							\
  }									\
									\
  flgr1d_arith_sup_##dtype(pout[j],tmp0,tmp1);				\
									\
  flgr1d_destroy(tmp);							\
  flgr1d_destroy(tmp0);							\
  flgr1d_destroy(tmp1);							\
  flgr1d_destroy(tmp2)


void flgr2d_dilate_8_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgBIT);
}
void flgr2d_dilate_8_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgUINT8);
}
void flgr2d_dilate_8_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgUINT16);
}
void flgr2d_dilate_8_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgUINT32);
}
void flgr2d_dilate_8_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgINT8);
}
void flgr2d_dilate_8_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgINT16);
}
void flgr2d_dilate_8_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgINT32);
}
void flgr2d_dilate_8_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgFLOAT32);
}
void flgr2d_dilate_8_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_DILATE_8_CONNEXITY(fgFLOAT64);
}



////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Gradient Plus
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

void flgr2d_gradient_outer_8_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_8_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_8_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,datsrc);  
}



void flgr2d_gradient_outer_6_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_6_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_6_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,datsrc);  
}




void flgr2d_gradient_outer_4_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,datsrc);  
}
void flgr2d_gradient_outer_4_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_4_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,datsrc);  
}




////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Gradient
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

void flgr2d_gradient_thick_8_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgBIT(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgUINT8(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgUINT16(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgUINT32(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgINT8(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgINT16(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgINT32(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgFLOAT32(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_8_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_8_connexity_fgFLOAT64(tmp,datsrc);
  flgr2d_dilate_8_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}









void flgr2d_gradient_thick_6_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgBIT(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgUINT8(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgUINT16(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgUINT32(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgINT8(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgINT16(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgINT32(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgFLOAT32(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_6_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_6_connexity_fgFLOAT64(tmp,datsrc);
  flgr2d_dilate_6_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}









void flgr2d_gradient_thick_4_connexity_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_4_connexity_fgBIT(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgBIT(datdest,datsrc);
  flgr2d_arith_xor_fgBIT(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_4_connexity_fgUINT8(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgUINT8(datdest,datsrc);
  flgr2d_arith_sub_fgUINT8(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_4_connexity_fgUINT16(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgUINT16(datdest,datsrc);
  flgr2d_arith_sub_fgUINT16(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_4_connexity_fgUINT32(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgUINT32(datdest,datsrc);
  flgr2d_arith_sub_fgUINT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_4_connexity_fgINT8(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgINT8(datdest,datsrc);
  flgr2d_arith_sub_fgINT8(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
  
  flgr2d_erode_4_connexity_fgINT16(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgINT16(datdest,datsrc);
  flgr2d_arith_sub_fgINT16(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
 
  flgr2d_erode_4_connexity_fgINT32(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgINT32(datdest,datsrc);
  flgr2d_arith_sub_fgINT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
 
  flgr2d_erode_4_connexity_fgFLOAT32(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgFLOAT32(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}
void flgr2d_gradient_thick_4_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Data2D *tmp;

  FLGR_DECLARE_FUNCTION;

  tmp = flgr2d_create_pixmap(datdest->size_y,datdest->size_x,datdest->spp,datdest->type);
 
  flgr2d_erode_4_connexity_fgFLOAT64(tmp,datsrc);
  flgr2d_dilate_4_connexity_fgFLOAT64(datdest,datsrc);
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,tmp);

  flgr2d_destroy(tmp);
}







////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Erosion Dilation optimised
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
#define FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(dtype,erodil)		\
  int i;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  if(size<1) {								\
    flgr2d_copy(datdest,datsrc);					\
    return;								\
  }									\
									\
  flgr2d_##erodil##_8_connexity_##dtype(datdest,datsrc);		\
  for(i=1 ; i<size ; i++)						\
    flgr2d_##erodil##_8_connexity_##dtype(datdest,datdest);		\
									\
  return

#define FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(dtype,erodil)		\
  int i;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  if(size<1) {								\
    flgr2d_copy(datdest,datsrc);					\
    return;								\
  }									\
									\
  flgr2d_##erodil##_4_connexity_##dtype(datdest,datsrc);		\
  for(i=1 ; i<size ; i++)						\
    flgr2d_##erodil##_4_connexity_##dtype(datdest,datdest);		\
									\
  return

#define FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(dtype,erodil)		\
  int i;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  if(size<1) {								\
    flgr2d_copy(datdest,datsrc);					\
    return;								\
  }									\
									\
  flgr2d_##erodil##_6_connexity_##dtype(datdest,datsrc);		\
  for(i=1 ; i<size ; i++)						\
    flgr2d_##erodil##_6_connexity_##dtype(datdest,datdest);		\
									\
  return

void flgr2d_erode_square_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgBIT,erode);
}
void flgr2d_erode_square_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgUINT8,erode);
}
void flgr2d_erode_square_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgUINT16,erode);
}
void flgr2d_erode_square_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgUINT32,erode);
}
void flgr2d_erode_square_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgINT8,erode);
}
void flgr2d_erode_square_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgINT16,erode);
}
void flgr2d_erode_square_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgINT32,erode);
}
void flgr2d_erode_square_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgFLOAT32,erode);
}
void flgr2d_erode_square_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgFLOAT64,erode);
}


void flgr2d_erode_cross_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgBIT,erode);
}
void flgr2d_erode_cross_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgUINT8,erode);
}
void flgr2d_erode_cross_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgUINT16,erode);
}
void flgr2d_erode_cross_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgUINT32,erode);
}
void flgr2d_erode_cross_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgINT8,erode);
}
void flgr2d_erode_cross_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgINT16,erode);
}
void flgr2d_erode_cross_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgINT32,erode);
}
void flgr2d_erode_cross_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgFLOAT32,erode);
}
void flgr2d_erode_cross_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgFLOAT64,erode);
}


void flgr2d_erode_hexa_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgBIT,erode);
}
void flgr2d_erode_hexa_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgUINT8,erode);
}
void flgr2d_erode_hexa_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgUINT16,erode);
}
void flgr2d_erode_hexa_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgUINT32,erode);
}
void flgr2d_erode_hexa_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgINT8,erode);
}
void flgr2d_erode_hexa_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgINT16,erode);
}
void flgr2d_erode_hexa_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgINT32,erode);
}
void flgr2d_erode_hexa_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgFLOAT32,erode);
}
void flgr2d_erode_hexa_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgFLOAT64,erode);
}



#define FLGR_MACRO_ERODE_DILATE_OCTAGON(dtype,erodil)		\
  int i;							\
  double size_square  = ((double) (size)) / (1+sqrt(2));	\
  double size_square2 = floor(size_square);			\
  int nbsqr = (int) ((size_square-size_square2) < 0.5f ?	\
		     size_square2 : (size_square2+1));		\
								\
  FLGR_DECLARE_FUNCTION;					\
								\
								\
  flgr2d_##erodil##_4_connexity_##dtype(datdest,datsrc);	\
  for(i=1 ; i<size-nbsqr ; i++) {				\
    flgr2d_##erodil##_4_connexity_##dtype(datdest,datdest);	\
  }								\
								\
  for(i=0 ; i<nbsqr ; i++) {					\
    flgr2d_##erodil##_8_connexity_##dtype(datdest,datdest);	\
  }								\
								\
  return;


void flgr2d_erode_octagon_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgBIT,erode);
}
void flgr2d_erode_octagon_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgUINT8,erode);
}
void flgr2d_erode_octagon_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgUINT16,erode);
}
void flgr2d_erode_octagon_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgUINT32,erode);
}
void flgr2d_erode_octagon_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgINT8,erode);
}
void flgr2d_erode_octagon_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgINT16,erode);
}
void flgr2d_erode_octagon_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgINT32,erode);
}
void flgr2d_erode_octagon_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgFLOAT32,erode);
}
void flgr2d_erode_octagon_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgFLOAT64,erode);
}



////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Dilation of size N by a square (2N+1)x(2N+1)
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
void flgr2d_dilate_square_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgBIT,dilate);
}
void flgr2d_dilate_square_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgUINT8,dilate);
}
void flgr2d_dilate_square_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgUINT16,dilate);
}
void flgr2d_dilate_square_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgUINT32,dilate);
}
void flgr2d_dilate_square_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgINT8,dilate);
}
void flgr2d_dilate_square_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgINT16,dilate);
}
void flgr2d_dilate_square_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgINT32,dilate);
}
void flgr2d_dilate_square_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgFLOAT32,dilate);
}
void flgr2d_dilate_square_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_SQUARE(fgFLOAT64,dilate);
}



void flgr2d_dilate_cross_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgBIT,dilate);
}
void flgr2d_dilate_cross_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgUINT8,dilate);
}
void flgr2d_dilate_cross_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgUINT16,dilate);
}
void flgr2d_dilate_cross_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgUINT32,dilate);
}
void flgr2d_dilate_cross_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgINT8,dilate);
}
void flgr2d_dilate_cross_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgINT16,dilate);
}
void flgr2d_dilate_cross_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgINT32,dilate);
}
void flgr2d_dilate_cross_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgFLOAT32,dilate);
}
void flgr2d_dilate_cross_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_CROSS(fgFLOAT64,dilate);
}



void flgr2d_dilate_hexa_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgBIT,dilate);
}
void flgr2d_dilate_hexa_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgUINT8,dilate);
}
void flgr2d_dilate_hexa_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgUINT16,dilate);
}
void flgr2d_dilate_hexa_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgUINT32,dilate);
}
void flgr2d_dilate_hexa_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgINT8,dilate);
}
void flgr2d_dilate_hexa_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgINT16,dilate);
}
void flgr2d_dilate_hexa_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgINT32,dilate);
}
void flgr2d_dilate_hexa_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgFLOAT32,dilate);
}
void flgr2d_dilate_hexa_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OPTIM_HEXA(fgFLOAT64,dilate);
}




void flgr2d_dilate_octagon_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgBIT,dilate);
}
void flgr2d_dilate_octagon_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgUINT8,dilate);
}
void flgr2d_dilate_octagon_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgUINT16,dilate);
}
void flgr2d_dilate_octagon_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgUINT32,dilate);
}
void flgr2d_dilate_octagon_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgINT8,dilate);
}
void flgr2d_dilate_octagon_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgINT16,dilate);
}
void flgr2d_dilate_octagon_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgINT32,dilate);
}
void flgr2d_dilate_octagon_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgFLOAT32,dilate);
}
void flgr2d_dilate_octagon_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_MACRO_ERODE_DILATE_OCTAGON(fgFLOAT64,dilate);
}



////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// openning of size N 
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
void flgr2d_open_square_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_square_fgBIT(datdest,datdest,size);  
}
void flgr2d_open_square_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_square_fgUINT8(datdest,datdest,size); 
}
void flgr2d_open_square_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_square_fgUINT16(datdest,datdest,size); 
}
void flgr2d_open_square_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_square_fgUINT32(datdest,datdest,size); 
}
void flgr2d_open_square_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_square_fgINT8(datdest,datdest,size); 
}
void flgr2d_open_square_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_square_fgINT16(datdest,datdest,size); 
}
void flgr2d_open_square_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_square_fgINT32(datdest,datdest,size); 
}
void flgr2d_open_square_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_square_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_open_square_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_square_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_open_square(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_square,datdest,datsrc,size);
}


void flgr2d_open_cross_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_cross_fgBIT(datdest,datdest,size);  
}
void flgr2d_open_cross_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_cross_fgUINT8(datdest,datdest,size); 
}
void flgr2d_open_cross_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_cross_fgUINT16(datdest,datdest,size); 
}
void flgr2d_open_cross_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_cross_fgUINT32(datdest,datdest,size); 
}
void flgr2d_open_cross_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_cross_fgINT8(datdest,datdest,size); 
}
void flgr2d_open_cross_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_cross_fgINT16(datdest,datdest,size); 
}
void flgr2d_open_cross_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_cross_fgINT32(datdest,datdest,size); 
}
void flgr2d_open_cross_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_cross_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_open_cross_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_cross_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_open_cross(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_cross,datdest,datsrc,size);
}



void flgr2d_open_hexa_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgBIT(datdest,datdest,size);  
}
void flgr2d_open_hexa_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgUINT8(datdest,datdest,size); 
}
void flgr2d_open_hexa_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgUINT16(datdest,datdest,size); 
}
void flgr2d_open_hexa_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgUINT32(datdest,datdest,size); 
}
void flgr2d_open_hexa_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgINT8(datdest,datdest,size); 
}
void flgr2d_open_hexa_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgINT16(datdest,datdest,size); 
}
void flgr2d_open_hexa_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgINT32(datdest,datdest,size); 
}
void flgr2d_open_hexa_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_open_hexa_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_open_hexa(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_hexa,datdest,datsrc,size);
}



void flgr2d_open_octagon_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgBIT(datdest,datdest,size);  
}
void flgr2d_open_octagon_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgUINT8(datdest,datdest,size); 
}
void flgr2d_open_octagon_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgUINT16(datdest,datdest,size); 
}
void flgr2d_open_octagon_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgUINT32(datdest,datdest,size); 
}
void flgr2d_open_octagon_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgINT8(datdest,datdest,size); 
}
void flgr2d_open_octagon_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgINT16(datdest,datdest,size); 
}
void flgr2d_open_octagon_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgINT32(datdest,datdest,size); 
}
void flgr2d_open_octagon_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_open_octagon_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_open_octagon(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_octagon,datdest,datsrc,size);
}



////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// Closing of size N 
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
void flgr2d_close_square_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgBIT(datdest,datsrc,size);
  flgr2d_erode_square_fgBIT(datdest,datdest,size);  
}
void flgr2d_close_square_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_square_fgUINT8(datdest,datdest,size); 
}
void flgr2d_close_square_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_square_fgUINT16(datdest,datdest,size); 
}
void flgr2d_close_square_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_square_fgUINT32(datdest,datdest,size); 
}
void flgr2d_close_square_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgINT8(datdest,datsrc,size);
  flgr2d_erode_square_fgINT8(datdest,datdest,size); 
}
void flgr2d_close_square_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgINT16(datdest,datsrc,size);
  flgr2d_erode_square_fgINT16(datdest,datdest,size); 
}
void flgr2d_close_square_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgINT32(datdest,datsrc,size);
  flgr2d_erode_square_fgINT32(datdest,datdest,size); 
}
void flgr2d_close_square_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_square_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_close_square_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_square_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_close_square(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_square,datdest,datsrc,size);
}



void flgr2d_close_cross_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgBIT(datdest,datsrc,size);
  flgr2d_erode_cross_fgBIT(datdest,datdest,size);  
}
void flgr2d_close_cross_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_cross_fgUINT8(datdest,datdest,size); 
}
void flgr2d_close_cross_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_cross_fgUINT16(datdest,datdest,size); 
}
void flgr2d_close_cross_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_cross_fgUINT32(datdest,datdest,size); 
}
void flgr2d_close_cross_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgINT8(datdest,datsrc,size);
  flgr2d_erode_cross_fgINT8(datdest,datdest,size); 
}
void flgr2d_close_cross_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgINT16(datdest,datsrc,size);
  flgr2d_erode_cross_fgINT16(datdest,datdest,size); 
}
void flgr2d_close_cross_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgINT32(datdest,datsrc,size);
  flgr2d_erode_cross_fgINT32(datdest,datdest,size); 
}
void flgr2d_close_cross_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_cross_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_close_cross_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_cross_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_close_cross(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_cross,datdest,datsrc,size);
}



void flgr2d_close_hexa_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgBIT(datdest,datsrc,size);
  flgr2d_erode_hexa_fgBIT(datdest,datdest,size);  
}
void flgr2d_close_hexa_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_hexa_fgUINT8(datdest,datdest,size); 
}
void flgr2d_close_hexa_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_hexa_fgUINT16(datdest,datdest,size); 
}
void flgr2d_close_hexa_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_hexa_fgUINT32(datdest,datdest,size); 
}
void flgr2d_close_hexa_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgINT8(datdest,datsrc,size);
  flgr2d_erode_hexa_fgINT8(datdest,datdest,size); 
}
void flgr2d_close_hexa_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgINT16(datdest,datsrc,size);
  flgr2d_erode_hexa_fgINT16(datdest,datdest,size); 
}
void flgr2d_close_hexa_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgINT32(datdest,datsrc,size);
  flgr2d_erode_hexa_fgINT32(datdest,datdest,size); 
}
void flgr2d_close_hexa_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_hexa_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_close_hexa_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_hexa_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_close_hexa(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_hexa,datdest,datsrc,size);
}



void flgr2d_close_octagon_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgBIT(datdest,datsrc,size);
  flgr2d_erode_octagon_fgBIT(datdest,datdest,size);  
}
void flgr2d_close_octagon_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_octagon_fgUINT8(datdest,datdest,size); 
}
void flgr2d_close_octagon_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_octagon_fgUINT16(datdest,datdest,size); 
}
void flgr2d_close_octagon_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_octagon_fgUINT32(datdest,datdest,size); 
}
void flgr2d_close_octagon_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgINT8(datdest,datsrc,size);
  flgr2d_erode_octagon_fgINT8(datdest,datdest,size); 
}
void flgr2d_close_octagon_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgINT16(datdest,datsrc,size);
  flgr2d_erode_octagon_fgINT16(datdest,datdest,size); 
}
void flgr2d_close_octagon_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgINT32(datdest,datsrc,size);
  flgr2d_erode_octagon_fgINT32(datdest,datdest,size); 
}
void flgr2d_close_octagon_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_octagon_fgFLOAT32(datdest,datdest,size); 
}
void flgr2d_close_octagon_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_octagon_fgFLOAT64(datdest,datdest,size); 
}
FLGR_Ret flgr2d_close_octagon(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_octagon,datdest,datsrc,size);
}



////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// open Top Hat of size N by a square (2N+1)x(2N+1)
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

void flgr2d_open_tophat_square_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_square_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_square_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_square_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_square_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_square_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_square_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_square_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_square_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_square_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_square_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_square_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datsrc,datdest);
}
FLGR_Ret flgr2d_open_tophat_square(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_tophat_square,datdest,datsrc,size);
}






void flgr2d_open_tophat_cross_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_cross_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_cross_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_cross_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_cross_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_cross_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_cross_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_cross_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_cross_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_cross_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_cross_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_cross_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datsrc,datdest);
}
FLGR_Ret flgr2d_open_tophat_cross(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_tophat_cross,datdest,datsrc,size);
}





void flgr2d_open_tophat_hexa_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_hexa_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_hexa_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_hexa_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datsrc,datdest);
}
FLGR_Ret flgr2d_open_tophat_hexa(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_tophat_hexa,datdest,datsrc,size);
}








void flgr2d_open_tophat_octagon_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgBIT(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgUINT8(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgUINT16(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgUINT32(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgINT8(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgINT16(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgINT32(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgFLOAT32(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datsrc,datdest);
}
void flgr2d_open_tophat_octagon_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_erode_octagon_fgFLOAT64(datdest,datsrc,size);
  flgr2d_dilate_octagon_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datsrc,datdest);
}
FLGR_Ret flgr2d_open_tophat_octagon(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_open_tophat_octagon,datdest,datsrc,size);
}



/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// close Top Hat of size N 
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
void flgr2d_close_tophat_square_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgBIT(datdest,datsrc,size);
  flgr2d_erode_square_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_square_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_square_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_square_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgINT8(datdest,datsrc,size);
  flgr2d_erode_square_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgINT16(datdest,datsrc,size);
  flgr2d_erode_square_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgINT32(datdest,datsrc,size);
  flgr2d_erode_square_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_square_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_square_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_square_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_square_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,datsrc);
}
FLGR_Ret flgr2d_close_tophat_square(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_tophat_square,datdest,datsrc,size);
}





void flgr2d_close_tophat_cross_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgBIT(datdest,datsrc,size);
  flgr2d_erode_cross_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_cross_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_cross_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_cross_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgINT8(datdest,datsrc,size);
  flgr2d_erode_cross_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgINT16(datdest,datsrc,size);
  flgr2d_erode_cross_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgINT32(datdest,datsrc,size);
  flgr2d_erode_cross_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_cross_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_cross_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_cross_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_cross_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,datsrc);
}
FLGR_Ret flgr2d_close_tophat_cross(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_tophat_cross,datdest,datsrc,size);
}





void flgr2d_close_tophat_hexa_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgBIT(datdest,datsrc,size);
  flgr2d_erode_hexa_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_hexa_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_hexa_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_hexa_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgINT8(datdest,datsrc,size);
  flgr2d_erode_hexa_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgINT16(datdest,datsrc,size);
  flgr2d_erode_hexa_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgINT32(datdest,datsrc,size);
  flgr2d_erode_hexa_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_hexa_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_hexa_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_hexa_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_hexa_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,datsrc);
}
FLGR_Ret flgr2d_close_tophat_hexa(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_tophat_hexa,datdest,datsrc,size);
}




void flgr2d_close_tophat_octagon_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgBIT(datdest,datsrc,size);
  flgr2d_erode_octagon_fgBIT(datdest,datdest,size);  
  flgr2d_arith_xor_fgBIT(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgUINT8(datdest,datsrc,size);
  flgr2d_erode_octagon_fgUINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgUINT16(datdest,datsrc,size);
  flgr2d_erode_octagon_fgUINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgUINT32(datdest,datsrc,size);
  flgr2d_erode_octagon_fgUINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgUINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgINT8(datdest,datsrc,size);
  flgr2d_erode_octagon_fgINT8(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT8(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgINT16(datdest,datsrc,size);
  flgr2d_erode_octagon_fgINT16(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT16(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgINT32(datdest,datsrc,size);
  flgr2d_erode_octagon_fgINT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgINT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgFLOAT32(datdest,datsrc,size);
  flgr2d_erode_octagon_fgFLOAT32(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT32(datdest,datdest,datsrc);
}
void flgr2d_close_tophat_octagon_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  flgr2d_dilate_octagon_fgFLOAT64(datdest,datsrc,size);
  flgr2d_erode_octagon_fgFLOAT64(datdest,datdest,size);  
  flgr2d_arith_sub_fgFLOAT64(datdest,datdest,datsrc);
}
FLGR_Ret flgr2d_close_tophat_octagon(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, int size) {
  FLGR_DECLARE_FUNCTION;
  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_close_tophat_octagon,datdest,datsrc,size);
}






/******************************************************
 ****************** Median Filter *********************
 ******************************************************/

#define FLGR_MACRO_SORT_TWO_L(dtype, lineOutMin, lineOutMax, lineIn1, lineIn2) \
  flgr1d_arith_inf_##dtype(lineOutMin,lineIn1,lineIn2);			\
  flgr1d_arith_sup_##dtype(lineOutMax,lineIn1,lineIn2)


#define FLGR_MACRO_MEDIAN_8_CONNEXITY(dtype)				\
  FLGR_Data1D *lineTmp1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp3 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp4 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp5 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp6 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp7 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp8 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineTmp9 = flgr1d_create_signal_from(datsrc->row[0]);	\
									\
  FLGR_Data1D *lineReg1 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg2 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg3 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg4 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg5 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg6 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg7 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg8 = flgr1d_create_signal_from(datsrc->row[0]);	\
  FLGR_Data1D *lineReg9 = flgr1d_create_signal_from(datsrc->row[0]);	\
									\
  FLGR_Data1D **pout = datdest->row;					\
  FLGR_Data1D **pin = datsrc->row;					\
  FLGR_Vector *vec_min = flgr_vector_create(datsrc->spp,datsrc->type);	\
  FLGR_Vector *vec_max = flgr_vector_create(datsrc->spp,datsrc->type);	\
  FLGR_Vector *vec1, *vec2;						\
  dtype min = MIN_##dtype;						\
  dtype max = MAX_##dtype;						\
  int i,k;								\
  									\
  FLGR_DECLARE_FUNCTION;						\
  									\
  flgr_vector_populate_from_scalar_##dtype(vec_min,min);		\
  flgr_vector_populate_from_scalar_##dtype(vec_max,max);		\
  									\
  vec1 = vec_max;							\
  vec2 = vec_min;							\
  									\
  flgr1d_shift_right_##dtype(lineTmp4,pin[0],1, vec1);			\
  flgr1d_copy_##dtype##_##dtype(lineTmp5,pin[0]);			\
  flgr1d_shift_left_##dtype(lineTmp6,pin[0],1,vec1);			\
  									\
  flgr1d_shift_right_##dtype(lineTmp7,pin[1],1,vec2);			\
  flgr1d_copy_##dtype##_##dtype(lineTmp8,pin[1]);			\
  flgr1d_shift_left_##dtype(lineTmp9,pin[1],1,vec2);			\
  									\
  /* Get Median first two lines */					\
  for(k = 0 ; k<3 ; k++) {						\
    flgr1d_copy_##dtype##_##dtype(lineReg4, lineTmp4);			\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg5,lineReg6,lineTmp5,lineTmp6);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg7,lineReg8,lineTmp7,lineTmp8);	\
    flgr1d_copy_##dtype##_##dtype(lineReg9, lineTmp9);			\
    									\
    FLGR_MACRO_SORT_TWO_L(dtype,lineTmp4,lineTmp5,lineReg4,lineReg5);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineTmp6,lineTmp7,lineReg6,lineReg7);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineTmp8,lineTmp9,lineReg8,lineReg9);	\
  }									\
  flgr1d_copy_##dtype##_##dtype(pout[0], lineTmp7);			\
  									\
  									\
  for(i=1 ; i<datdest->size_y-1 ; i++) {				\
    									\
    vec1 = ((i%2)==0) ? vec_max : vec_min;				\
    vec2 = ((i%2)==1) ? vec_max : vec_min;				\
    									\
    flgr1d_shift_right_##dtype(lineTmp1,pin[i-1],1,vec2);		\
    flgr1d_copy_##dtype##_##dtype(lineTmp2,pin[i-1]);			\
    flgr1d_shift_left_##dtype(lineTmp3,pin[i-1],1,vec2);		\
    									\
    flgr1d_shift_right_##dtype(lineTmp4,pin[i],1,vec1);			\
    flgr1d_copy_##dtype##_##dtype(lineTmp5,pin[i]);			\
    flgr1d_shift_left_##dtype(lineTmp6,pin[i],1,vec1);			\
    									\
    flgr1d_shift_right_##dtype(lineTmp7,pin[i+1],1,vec2);		\
    flgr1d_copy_##dtype##_##dtype(lineTmp8,pin[i+1]);			\
    flgr1d_shift_left_##dtype(lineTmp9,pin[i+1],1,vec2);		\
  									\
    for(k = 0 ; k<4 ; k++) {						\
      flgr1d_copy_##dtype##_##dtype(lineReg1, lineTmp1);		\
      FLGR_MACRO_SORT_TWO_L(dtype,lineReg2,lineReg3,lineTmp2,lineTmp3);	\
      FLGR_MACRO_SORT_TWO_L(dtype,lineReg4,lineReg5,lineTmp4,lineTmp5);	\
      FLGR_MACRO_SORT_TWO_L(dtype,lineReg6,lineReg7,lineTmp6,lineTmp7);	\
      FLGR_MACRO_SORT_TWO_L(dtype,lineReg8,lineReg9,lineTmp8,lineTmp9);	\
    									\
      FLGR_MACRO_SORT_TWO_L(dtype,lineTmp1,lineTmp2,lineReg1,lineReg2);	\
      FLGR_MACRO_SORT_TWO_L(dtype,lineTmp3,lineTmp4,lineReg3,lineReg4);	\
      FLGR_MACRO_SORT_TWO_L(dtype,lineTmp5,lineTmp6,lineReg5,lineReg6);	\
      FLGR_MACRO_SORT_TWO_L(dtype,lineTmp7,lineTmp8,lineReg7,lineReg8);	\
      flgr1d_copy_##dtype##_##dtype(lineTmp9, lineReg9);		\
    }									\
  									\
    flgr1d_copy_##dtype##_##dtype(lineReg1, lineTmp1);			\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg2,lineReg3,lineTmp2,lineTmp3);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg4,lineReg5,lineTmp4,lineTmp5);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg6,lineReg7,lineTmp6,lineTmp7);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg8,lineReg9,lineTmp8,lineTmp9);	\
  									\
    flgr1d_copy_##dtype##_##dtype(pout[i], lineReg5);			\
  }									\
  									\
  i = datdest->size_y-1;						\
  									\
  vec1 = ((i%2)==0) ? vec_max : vec_min;				\
  vec2 = ((i%2)==1) ? vec_max : vec_min;				\
  									\
  flgr1d_shift_right_##dtype(lineTmp4,pin[i-1],1,vec2);			\
  flgr1d_copy_##dtype##_##dtype(lineTmp5,pin[i-1]);			\
  flgr1d_shift_left_##dtype(lineTmp6,pin[i-1],1,vec2);			\
  									\
  flgr1d_shift_right_##dtype(lineTmp7,pin[i],1,vec1);			\
  flgr1d_copy_##dtype##_##dtype(lineTmp8,pin[i]);			\
  flgr1d_shift_left_##dtype(lineTmp9,pin[i],1,vec1);			\
  									\
  /* Get Median first two lines */					\
  for(k = 0 ; k<3 ; k++) {						\
    flgr1d_copy_##dtype##_##dtype(lineReg4, lineTmp4);			\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg5,lineReg6,lineTmp5,lineTmp6);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg5,lineReg6,lineTmp5,lineTmp6);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg7,lineReg8,lineTmp7,lineTmp8);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineReg7,lineReg8,lineTmp7,lineTmp8);	\
    flgr1d_copy_##dtype##_##dtype(lineReg9, lineTmp9);			\
    									\
    FLGR_MACRO_SORT_TWO_L(dtype,lineTmp4,lineTmp5,lineReg4,lineReg5);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineTmp6,lineTmp7,lineReg6,lineReg7);	\
    FLGR_MACRO_SORT_TWO_L(dtype,lineTmp8,lineTmp9,lineReg8,lineReg9);	\
  }									\
  									\
  if((i%2)==1) {							\
    flgr1d_copy_##dtype##_##dtype(pout[i], lineTmp6);			\
  } else {								\
    flgr1d_copy_##dtype##_##dtype(pout[i], lineTmp7);			\
  }									\
  									\
  flgr_vector_destroy(vec_min);						\
  flgr_vector_destroy(vec_max);						\
  flgr1d_destroy(lineTmp1);						\
  flgr1d_destroy(lineTmp2);						\
  flgr1d_destroy(lineTmp3);						\
  flgr1d_destroy(lineTmp4);						\
  flgr1d_destroy(lineTmp5);						\
  flgr1d_destroy(lineTmp6);						\
  flgr1d_destroy(lineTmp7);						\
  flgr1d_destroy(lineTmp8);						\
  flgr1d_destroy(lineTmp9);						\
  flgr1d_destroy(lineReg1);						\
  flgr1d_destroy(lineReg2);						\
  flgr1d_destroy(lineReg3);						\
  flgr1d_destroy(lineReg4);						\
  flgr1d_destroy(lineReg5);						\
  flgr1d_destroy(lineReg6);						\
  flgr1d_destroy(lineReg7);						\
  flgr1d_destroy(lineReg8);						\
  flgr1d_destroy(lineReg9)
 
void flgr2d_median_8_connexity_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgUINT8);
}
void flgr2d_median_8_connexity_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgUINT16);
}
void flgr2d_median_8_connexity_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgUINT32);
}
void flgr2d_median_8_connexity_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgINT8);
}
void flgr2d_median_8_connexity_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgINT16);
}
void flgr2d_median_8_connexity_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgINT32);
}
void flgr2d_median_8_connexity_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgFLOAT32);
}
void flgr2d_median_8_connexity_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MEDIAN_8_CONNEXITY(fgFLOAT64);
}

